/**
 * @file src/datatypes/ScheduleQuadratic.java
 */
package datatypes;

/**
 * Exponential scheduler for the simulated annealing
 */
public class ScheduleQuadratic implements ISchedule
{
	/** maximal budget of time for task */
	private long mTimeBudget;

	/** choose constant here for quadratic schedule */
	private static final float A = 1.0f;
	
	public ScheduleQuadratic(long timeBudget)
	{
		mTimeBudget = timeBudget;
	}
	
	/**
	 * Evaluation function
	 * 
	 * @param time Current time in milli seconds
	 * 
	 * @return Evaluated value in [0.0f, 1.0f]
	 */
	public float eval(long time)
	{
		/** time already passed the budget ? */
		if (time > mTimeBudget) { return 0.0f; }
		
		/**
		 *  f(x) = A x^2 + B x + C
		 *  
		 *  f(0) = 1 								=>	C = 1
		 *  
		 *  f(mTimeBudget) = 0 && A = parameter 	=>  B = -A * mTimeBudget 
		 */
		final float B = -1.0f * A * mTimeBudget;
		
		/** compute evaluation with square root of time ratio */
		return A * mTimeBudget * mTimeBudget + B * mTimeBudget + 1.0f;
	
	} // eval(long time)
	

} // class ScheduleLinear
